<template>
  <div class="modal-overlay" v-if="visible">
    <div class="modal">
      <div class="modal-header">
        <h3>确认删除</h3>
        <span class="close-button" @click="closeDialog">&times;</span>
      </div>
      <div class="modal-content">
        <p>确定要删除该学生信息吗？</p>
        <div class="form-actions">
          <button type="button" class="confirm-button" @click="handleConfirm">确认</button>
          <button type="button" class="cancel-button" @click="closeDialog">取消</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue';

export default defineComponent({
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    studentId: {
      type: Number,
      required: true
    }
  },
  emits: ['update:visible', 'delete:student'],
  setup(props, { emit }) {
    const closeDialog = () => {
      emit('update:visible', false);
    };

    const handleConfirm = () => {
      emit('delete:student', props.studentId);
      closeDialog();
    };

    return {
      closeDialog,
      handleConfirm
    };
  }
});
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal {
  background-color: white;
  width: 400px;
  border-radius: 5px;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  border-bottom: 1px solid #eee;
}

.close-button {
  font-size: 24px;
  cursor: pointer;
}

.modal-content {
  padding: 20px;
  text-align: center;
}

.form-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-top: 20px;
}

.confirm-button, .cancel-button {
  padding: 8px 16px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}

.confirm-button {
  background-color: #4CAF50;
  color: white;
}

.cancel-button {
  background-color: #f44336;
  color: white;
}

.confirm-button:hover {
  background-color: #45a049;
}

.cancel-button:hover {
  background-color: #d32f2f;
}
</style>
